class Solution {
public:
    vector<int> partitionLabels(string s) {
        vector<int> hash(26, 0);
        for (int i = 0; i < s.size(); i++) {
            hash[s[i] - 'a'] = i;
        }
        vector<int> result;
        int left = 0, right = 0;
        for (int i = 0; i < s.size(); i++) {
            right = max(right, hash[s[i] - 'a']);
            if (i == right) {
                result.push_back(right - left + 1);
                left = right + 1;
            }
        }
        return result;
    }
};
